package com.leyou.item.web;

import com.leyou.common.vo.PageResult;
import com.leyou.common.vo.ResponseResult;
import com.leyou.item.pojo.Brand;
import com.leyou.item.pojo.Category;
import com.leyou.item.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;
import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @GetMapping("/page")
    public ResponseEntity<ResponseResult<PageResult<Brand>>> querySomeWithPage(
            @RequestParam(value = "key") String key,
            @RequestParam(value = "sortBy") String sortBy,
            @RequestParam(value = "order") boolean order,
            @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        PageResult<Brand> result = brandService.querySomeWithPage(key, sortBy, order,currentPage, pageSize);
        return ResponseEntity.ok(ResponseResult.success(result));
    }

    @PostMapping
    public ResponseEntity<ResponseResult<Object>> addBrand(@RequestBody Brand brand, @RequestBody List<Integer> cids) {
        brandService.addBrand(brand, cids);
        return ResponseEntity.ok(ResponseResult.success(null));
    }
}
